package com.zhuiyun.project.api.article.service.impl;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.zhuiyun.project.api.article.entity.Article;
import com.zhuiyun.project.api.article.entity.ArticleAudit;
import com.zhuiyun.project.api.article.mapper.ArticleReviewMapper;
import com.zhuiyun.project.api.article.model.ArticleAuditModel;
import com.zhuiyun.project.api.article.service.ArticleReviewService;

import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.util.pageUtil.MybatisPageHelper;
import com.zhuiyun.project.util.pageUtil.PageRequest;
import com.zhuiyun.project.util.pageUtil.PageResult;
import com.zhuiyun.project.websocket.Message;
import com.zhuiyun.project.websocket.SocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.websocket.Session;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @ClassName ArticleReviewServiceImpl
 * @Description TODO
 * @Author maomao
 * @Date 2023/6/15 10:38
 **/

@Service
public class ArticleReviewServiceImpl implements ArticleReviewService {

    @Autowired
    ArticleReviewMapper articleReviewMapper;
    @Autowired
    private SocketServer socketServer;


    /**
     * 查询发布完待审核的文章
     * @author 温
     * @date 2023/7/21 15:32
     * @parameter [pageRequest, doctorName, articleTitle]
     * @return com.zhuiyun.project.util.pageUtil.PageResult
     */
    @Override
    public PageResult getArticle(PageRequest pageRequest,  String userName, String articleTitle) {
        MybatisPageHelper.startPage(pageRequest);// 使用MybatisPageHelper实现分页功能，设置分页信息
        List<Article> articleList = articleReviewMapper.getArticle(pageRequest, userName, articleTitle);// 调用ArticleReviewMapper的getArticle方法查询文章列表\
        return MybatisPageHelper.getPageResult(articleList);// 将查询结果封装为PageResult对象并返回
    }

    /**
     * 文章审核通过
     * @author 温
     * @date 2023/7/17 19:47
     * @parameter [articleAudit]
     * @return com.zhuiyun.project.common.response.CommonResult
     */
    @Override
    public CommonResult addArticleStatus(ArticleAudit articleAudit) {
            int i = articleReviewMapper.addArticleStatus(articleAudit);
            int i1 = articleReviewMapper.updateArticleStatus(articleAudit.getId());
            return CommonResult.ok(200);
    }

    /**
     * 文章审核驳回
     * @author 温
     * @date 2023/7/17 19:48
     * @parameter [ArticleAudit]
     * @return com.zhuiyun.project.common.response.CommonResult
     */
    @Override
    public CommonResult addArticleUpdate(ArticleAudit articleAudits) {
            int i = articleReviewMapper.updateArticleStatuss(articleAudits.getId());
            int i1 = articleReviewMapper.addArticleUpdate(articleAudits);
            return CommonResult.ok(200);
    }

    /**
     * 审核记录查询
     * @author 温
     * @date 2023/7/18 11:17
     * @parameter [articleTitle, pageRequest]
     * @return com.zhuiyun.project.util.pageUtil.PageResult
     */
    @Override
    public PageResult ArticleAuditList(String articleTitle,PageRequest pageRequest) {
        MybatisPageHelper.startPage(pageRequest);
        List<ArticleAuditModel> articleAuditModels = articleReviewMapper.ArticleAuditList(articleTitle,pageRequest);
        return MybatisPageHelper.getPageResult(articleAuditModels);
    }


}
